package Utility;

import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.net.Socket;

import Messages.Message;

public class PaxosMessageWriterImpl implements PaxosMessageWriter {

	/**
	 * Writes PaxosMessage to the given socket.
	 */
	@Override
	public void writeMessage(Socket clientSocket, Message messageToBeWritten) {
		try {
			System.out.println("Writing the message : " + messageToBeWritten.getMessageType().name());
			OutputStream serverSockOutput = clientSocket.getOutputStream();
			ObjectOutputStream oos = new ObjectOutputStream(serverSockOutput);
			oos.writeObject(messageToBeWritten);
			oos.flush();
			//oos.close();
		} catch (Exception e) {
			System.err.println("Failed to write Paxos Message to socket");
			e.printStackTrace();
		}
	}
}
